package com.smartEdu.mybatis.typehandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

import com.smartEdu.utils.JsonUtil;

@MappedTypes({Object.class})  
@MappedJdbcTypes({JdbcType.VARCHAR}) 
public class JsonTypeHandler extends BaseTypeHandler<Object>{

	
	public Object getJsonObject(String columnValue){
		if (columnValue == null) {
			return null;
		}
		return JsonUtil.toObject(columnValue, Object.class);
	}

	@Override
	public Object getNullableResult(ResultSet arg0, String arg1) throws SQLException {
		return getJsonObject(arg0.getString(arg1));
	}

	@Override
	public Object getNullableResult(ResultSet arg0, int arg1) throws SQLException {
		return getJsonObject(arg0.getString(arg1));
	}

	@Override
	public Object getNullableResult(CallableStatement arg0, int arg1) throws SQLException {
		return getJsonObject(arg0.getString(arg1));
	}

	@Override
	public void setNonNullParameter(PreparedStatement arg0, int arg1, Object arg2, JdbcType arg3) throws SQLException {
		// TODO 自动生成的方法存根
		
	}

}
